/**
 * Module dependencies
 */
app.addRepository("modules/core/HopObject.js");
app.addRepository("modules/core/String.js");
app.addRepository("modules/helma/File.js")

/**
 * Check for important directories
 */
var checkProjectLayout = function() {
   var projectRoot = getProperty("hippo.projectRoot");
   var rootFile = new helma.File(projectRoot);
   res.debug(rootFile.isDirectory());
   
   var result = {};
   var dirs = getProperty("hippo.projectDirs").split(" ");
   for (var i = 0; i < dirs.length; i++) {
      if ((new helma.File(projectRoot + "/" + dirs[i])).isDirectory()) {
         result[dirs[i]] = true;
      } else {
         result[dirs[i]] = false;
      }
   }
   return result;
}

var checkStrictFilenaming = function() {
   var result = {};
   var checkInnerNaming = function(dir) {
      var files = dir.list(/^[^\.].*/);
      for (var i = 0; i < files.length; i++) {
         var file = new helma.File(dir.getAbsolutePath() + "/" + files[i]);
         if (file.isDirectory()) {
            if (files[i] == "skins") {
               var skinFiles = file.list(/^[^\.].*/);
               for (var u = 0; u < skinFiles.length; u++) {
                  if (skinFiles[u].endsWith(".skin")) {
                     result[ dir.getName() + "/skins/" + skinFiles[u] ] = true;
                  } else {
                     result[ dir.getName() + "/skins/" + skinFiles[u] ] = false;
                  }
               }
            } else {
               result [ dir.getName() + "/" + files[i] ] = false;
            }
         } else {
            if (files[i] == (dir.getName() + ".macros.js") || files[i] == (dir.getName() + ".actions.js") || files[i] == (dir.getName() + ".properties") || files[i] == "type.properties"
                     || files[i] == (dir.getName() + ".js") || files[i] == (dir.getName() + ".functions.js")) {
               result [ dir.getName() + "/" + files[i] ] = true;
            } else {
               result [ dir.getName() + "/" + files[i] ] = false;
            }
         }
      }   
   }
   
   var codeRoot = getProperty("hippo.projectRoot") + "/" + getProperty("hippo.projectCodeDir");
   var prototypes = (new helma.File(codeRoot)).list(/^[^\.].*/);
   
   for (var i = 0; i < prototypes.length; i++) {
      var file = prototypes[i];
      if (new helma.File(codeRoot + "/" + file).isFile()) {
         if (file == "app.properties" || file == "db.properties") {
            result[file] = true;
         } else {
            result[file] = false;
         }
      } else {
         checkInnerNaming(new helma.File(codeRoot + "/" + file));
      }
   }
   return result;
}